#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'多线程同时操作一个变量是怎么把内容改乱'

import threading

# 假设这是你的银行存款
balance = 0


def change_it(n):
    # 先存后取，结果应该为0:
    global balance
    balance = balance + n
    balance = balance - n


def run_thread(n):
    for i in range(1000000):
        change_it(n)


t1 = threading.Thread(target=run_thread, args=(5,))
t2 = threading.Thread(target=run_thread, args=(8,))
t1.start()
t2.start()
t1.join()
t2.join()
print(balance)
